const express = require("express");
const path = require("path");

const app = express();

/*---------配置静态路径--------*/
app.use(express.static(path.join(__dirname, "public")));


app.get("/test", (req, res, next)=>{
   setTimeout(()=>{
       res.send("success");
   }, 3000);
});

/*---------处理404错误--------*/
app.use((req, res, next)=>{
    let err = new Error("Error:404, the source is not found!");
    err.status = 404;
    next(err);
});

/*---------处理500错误--------*/
app.use((err, req, res, next)=>{
    res.status(err.status || 500).send(err.message);
    next();
});

module.exports = app;